package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsTitle  string `gorm:"type:char(100);index;not null;comment(商品标题)"`
	GoodsPrice  int    `gorm:"type:int(10);not null;comment(商品价格)"`
	GoodsStock  int    `gorm:"type:int(10);not null;comment(商品库存)"`
	GoodsCover  string `gorm:"type:varchar(255);comment(商品图片)"`
	GoodsStatus int    `gorm:"type:int(10);default:1;;comment(商品状态)"`
}

// CreateGoods 创建商品
func (g *Goods) CreateGoods() error {
	return Db.Create(&g).Error
}

// ListGoods 列表展示
func (g *Goods) ListGoods() (goods []*Goods, err error) {
	Db.Model(&g).Find(&goods)
	return nil, err
}

// GoodsDetail 商品详情
func (g *Goods) GoodsDetail(goodsId int) (good Goods, err error) {
	Db.Model(&g).Where("id", goodsId).First(&good)
	return
}
